home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / svgakt50.zip / SRC / SVGAKIT / PROFILE.C < prev    next >
C/C++ Source or Header  |  1994-08-23  |  9KB  |  326 lines

  1. /****************************************************************************
  2. *
  3. *                              The SuperVGA Kit
  4. *
  5. *                   Copyright (C) 1994 SciTech Software
  6. *                           All rights reserved.
  7. *
  8. * Filename:     $RCSfile: profile.c $
  9. * Version:      $Revision: 1.1 $
  10. *
  11. * Language:     ANSI C
  12. * Environment:  IBM PC (MSDOS) Real Mode and 16/32 bit Protected Mode.
  13. *
  14. * Description:  Simple program to profile the speed of certain operations
  15. *                for the SuperVGA Kit. This is great way to test the
  16. *                performance of different SuperVGA card and different
  17. *                compiler configurations. It is also helps to highlight
  18. *                where the 32 bit protected mode interface of UniVBE can
  19. *                be very beneficial for 32 bit application development.
  20. *
  21. *                Note, this library uses the Zen Timer Library for
  22. *                microsecond accuracy timing of the routines.
  23. *
  24. *               MUST be compiled in the large or flat models.
  25. *
  26. * $Id: profile.c 1.1 1994/08/22 12:27:00 kjb release $
  27. *
  28. ****************************************************************************/
  29.  
  30. #include <stdio.h>
  31. #include <stdlib.h>
  32. #include <string.h>
  33. #include <dos.h>
  34. #include <conio.h>
  35. #include "pmode.h"
  36. #include "svga.h"
  37. #include "ztimer.h"
  38.  
  39. /*----------------------------- Implementation ----------------------------*/
  40.  
  41. float    pixelTime;
  42. long    numPixels;
  43. float    pixelsPerSec;
  44. float    lineTime;
  45. long    numLines;
  46. float    linesPerSec;
  47. float    clearTime;
  48. long    numClears;
  49. float    clearsPerSec;
  50. float    bitBltTime;
  51. long    numBitBlts;
  52. float    bitBltsPerSec;
  53.  
  54. #include "version.c"
  55.  
  56. /* External assembly language routine to perform a full screen Blt from
  57.  * system memory, using fast REP MOVSD strings instructions for entire
  58.  * 64k banks - about as optimal as you will ever get for a full screen
  59.  * Blt.
  60.  */
  61.  
  62. extern void _cdecl bltImage(char *image,int numBanks,int lastBytes);
  63.  
  64. void profilePixels(void)
  65. /****************************************************************************
  66. *
  67. * Function:        profilePixels
  68. *
  69. * Description:    Tests the speed of pixel drawing, by filling the entire
  70. *                frame buffer with pixels.
  71. *
  72. ****************************************************************************/
  73. {
  74.     int        i,j,k,max;
  75.     long    step,color;
  76.  
  77.     switch (maxcolor) {
  78.         case 0xF:        max = 2;    break;
  79.         case 0xFF:
  80.         case 0x7FFF:
  81.         case 0xFFFF:    max = 5;    break;
  82.         default:        max = 5;
  83.         }
  84.  
  85.     clear(0);
  86.     step = (maxcolor <= 0xFF) ? 1 : maxcolor / max;
  87.     ULZTimerOn();
  88.     for (k = 0,color = 1; k < max; k++, color += step) {
  89.         for (j = 0; j <= maxy; j++)
  90.             for (i = 0; i <= maxx; i++)
  91.                 putPixel(i,j,color);
  92.         }
  93.     ULZTimerOff();
  94.     pixelTime = ULZTimerCount() * ULZTIMER_RES;
  95.     numPixels = (long)(maxx+1) * (maxy+1) * max;
  96.     pixelsPerSec = numPixels / pixelTime;
  97. }
  98.  
  99. int _random(int max)
  100. {
  101.     return (rand() % (max+1));
  102. }
  103.  
  104. #define    MAXLINES    1000
  105.  
  106. int x[MAXLINES];
  107. int y[MAXLINES];
  108.  
  109. void profileLines(void)
  110. /****************************************************************************
  111. *
  112. * Function:        profileLines
  113. *
  114. * Description:    Test the speed of line drawing in the specified video
  115. *                mode. We blast out a whole bunch of random lines as fast
  116. *                as possible.
  117. *
  118. ****************************************************************************/
  119. {
  120.     int        i,j,max;
  121.     long    step,color;
  122.  
  123.     switch (maxcolor) {
  124.         case 0xF:        max = 20;    break;
  125.         case 0xFF:
  126.         case 0x7FFF:
  127.         case 0xFFFF:    max = 30;    break;
  128.         default:        max = 20;
  129.         }
  130.  
  131.     srand(1000);
  132.     for (i = 0; i < MAXLINES; i++) {
  133.         x[i] = _random(maxx);
  134.         y[i] = _random(maxy);
  135.         }
  136.  
  137.     clear(0);
  138.     step = (maxcolor <= 0xFF) ? 1 : maxcolor / max;
  139.     ULZTimerOn();
  140.     for (j = 0, color = 1; j < max; j++, color += step) {
  141.         for (i = 0; i < MAXLINES-1; i++)
  142.             line(x[i],y[i],x[i+1],y[i+1],color);
  143.         }
  144.     ULZTimerOff();
  145.     lineTime = ULZTimerCount() * ULZTIMER_RES;
  146.     numLines = (long)MAXLINES * max;
  147.     linesPerSec = numLines / lineTime;
  148. }
  149.  
  150. void profileClears(void)
  151. /****************************************************************************
  152. *
  153. * Function:        profileClears
  154. *
  155. * Description:    Test the speed of screen clearing to a specific color.
  156. *
  157. ****************************************************************************/
  158. {
  159.     int        i,max;
  160.     long    step,color;
  161.  
  162.     switch (maxcolor) {
  163.         case 0xF:        max = 1000;    break;
  164.         case 0xFF:        max = 300;    break;
  165.         case 0x7FFF:
  166.         case 0xFFFF:    max = 150;    break;
  167.         case 0xFFFFFF:    max = 30;    break;
  168.         default:        max = 50;    break;
  169.         }
  170.  
  171.     step = (maxcolor <= 0xFF) ? 1 : maxcolor / max;
  172.     ULZTimerOn();
  173.     for (i = 0, color = 0; i < max; i++, color += step)
  174.         clear(color);
  175.     ULZTimerOff();
  176.     clearTime = ULZTimerCount() * ULZTIMER_RES;
  177.     numClears = max;
  178.     clearsPerSec = numClears / clearTime;
  179. }
  180.  
  181. void profileBitBlt(void)
  182. /****************************************************************************
  183. *
  184. * Function:        profileBitBlt
  185. *
  186. * Description:    Test the speed of blitting full size image from system RAM
  187. *                to video RAM.
  188. *
  189. *                NOTE: The bitBlt'ing routine used blt's and entire display
  190. *                      memory frame at a time, which is as optimal as you
  191. *                      can get. Thus the results of this profiling test will
  192. *                      give you a good idea of what you can expect as the
  193. *                      absolute best case in real world performance.
  194. *
  195. ****************************************************************************/
  196. {
  197.     int        i,numBanks,max;
  198.     uint    lastBytes;
  199.     ulong    imageSize;
  200.     uint    screenSel;
  201.     char    *image,*dst;
  202.  
  203.     switch (maxcolor) {
  204.         case 0xFF:      max = 150;  break;
  205.         case 0x7FFF:
  206.         case 0xFFFF:    max = 75;  break;
  207.         default:        max = 30;
  208.         }
  209.  
  210.     screenSel = PM_getVGASelector();
  211.     imageSize = (long)bytesperline * (maxy+1);
  212. #ifndef    PM386
  213.     if (imageSize > 0x10000) {
  214.         bitBltTime = -1;
  215.         return;
  216.         }
  217. #endif
  218.     numBanks = imageSize / 0x10000;
  219.     lastBytes = imageSize % 0x10000;
  220.     image = malloc(imageSize);
  221.     if (image == NULL) {
  222.         bitBltTime = -1;
  223.         return;
  224.         }
  225.  
  226.     // Copy the current image from the frame buffer into our system memory
  227.     // buffer (which will still contain an image from the profileLines()
  228.     // routine).
  229.  
  230.     dst = image;
  231.     for (i = 0; i < numBanks; i++) {        // Blt all full memory banks
  232.         setBank(i);
  233.         PM_memcpynf(dst,screenSel,0,0x10000);
  234.         dst += 0x10000;
  235.         }
  236.     if (lastBytes) {
  237.         setBank(i);
  238.         PM_memcpynf(dst,screenSel,0,lastBytes);    // Blt the last partial bank
  239.         }
  240.  
  241.     // Now blt the image from system RAM back to the video frame buffer
  242.     clear(0);
  243.     ULZTimerOn();
  244.     for (i = 0; i < max; i++)
  245.         bltImage(image,numBanks,lastBytes);
  246.     ULZTimerOff();
  247.     bitBltTime = ULZTimerCount() * ULZTIMER_RES;
  248.     numBitBlts = max;
  249.     bitBltsPerSec = numBitBlts / bitBltTime;
  250.  
  251.     free(image);
  252. }
  253.  
  254. void dumpMode(int mode)
  255. {
  256.     int        xres,yres,bytesperline,bitsperpixel,memmodel,maxpage;
  257.     long    pagesize;
  258.  
  259.     getSuperVGAModeInfo(mode,&xres,&yres,&bytesperline,&bitsperpixel,
  260.         &memmodel,&maxpage,&pagesize);
  261.     if (memmodel >= memPL)
  262.         printf("    %03X - %dx%d\t%d bits per pixel\n", mode,
  263.             xres, yres, bitsperpixel);
  264. }
  265.  
  266. void help(void)
  267. {
  268.     short    *modes;
  269.  
  270.     printf("Profile - SuperVGA Kit performance profiling program (Version %s)\n", version);
  271.     printf("          Copyright (C) 1994 SciTech Software\n\n");
  272.     printf("Usage: profile [mode]\n\n");
  273.     printf("Available modes are:\n");
  274.     dumpMode(0x0D);
  275.     dumpMode(0x10);
  276.     dumpMode(0x12);
  277.     dumpMode(0x13);
  278.     for (modes = modeList; *modes != -1; modes++)
  279.         dumpMode(*modes);
  280.     exit(1);
  281. }
  282.  
  283. int main(int argc, char *argv[])
  284. {
  285.     int    mode;
  286.  
  287.     if (initSuperVGA(false) < 0x102) {
  288.         printf("This program requires a VESA VBE 1.2 compatible SuperVGA. Try installing\n");
  289.         printf("the Universal VESA VBE for your video card, or contact your video card\n");
  290.         printf("vendor and ask for a suitable TSR\n");
  291.         exit(1);
  292.         }
  293.     if (argc != 2)
  294.         help();
  295.  
  296.     sscanf(argv[1], "%X", &mode);
  297.     ZTimerInit();
  298.  
  299.     if (setSuperVGAMode(mode)) {
  300.         profilePixels();
  301.         profileLines();
  302.         if (maxcolor > 0xF)
  303.             profileBitBlt();
  304.         profileClears();
  305.         restoreMode();
  306.  
  307.         printf("Profiling results for %dx%d %ld color (%s):\n",
  308.             maxx+1,maxy+1,maxcolor+1,
  309. #ifdef    PM386
  310.             "32 bit protected mode");
  311. #elif    defined(PM286)
  312.             "16 bit protected mode");
  313. #else
  314.             "16 bit real mode");
  315. #endif
  316.         printf("\n");
  317.         printf("%.1fs for %8ld pixels  (%.2f pixels/s)\n", pixelTime, numPixels, pixelsPerSec);
  318.         printf("%.1fs for %8ld lines   (%.2f lines/s)\n", lineTime, numLines, linesPerSec);
  319.         printf("%.1fs for %8ld clears  (%.2f clears/s)\n", clearTime, numClears, clearsPerSec);
  320.         if (maxcolor > 0xF && bitBltTime != -1)
  321.             printf("%.1fs for %8ld bitBlts (%.2f bitBlt/s)\n", bitBltTime, numBitBlts, bitBltsPerSec);
  322.         }
  323.     else printf("Could not set specified video mode\n");
  324.     return 0;
  325. }
  326.